package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;

public class Library {

    private static final String EMPTY_BOOK_LIST_MESSAGE = "No Books to List\n";
    private static final String EMPTY_MOVIE_LIST_MESSAGE = "No Movies to List\n";

    private final List<Book> books;
    private final List<Movie> movies;
    private final List<Customer> customers;

    public Library() {
        this.books = new ArrayList<Book>();
        this.movies = new ArrayList<Movie>();
        this.customers = new ArrayList<Customer>();
    }

    public List<Book> getBooks() {
        return books;
    }

    public List<Movie> getMovies() {
        return movies;
    }

    public String getBookListAsString() {
        return getItemListAsString(books, EMPTY_BOOK_LIST_MESSAGE);
    }

    public String getMovieListAsString() {
        return getItemListAsString(movies, EMPTY_MOVIE_LIST_MESSAGE);
    }

    private String getItemListAsString(List<? extends LibraryItem> items, String emptyMessage) {
        boolean empty = true;
        String listString = "";

        for (LibraryItem item : items) {
            if (!item.isCheckedOut()) {
                listString += item.toString() + "\n";
                empty = false;
            }
        }

        if (empty)
            return emptyMessage;
        return listString;
    }

    public List<Customer> getCustomers() {
        return customers;
    }
}
